home *** CD-ROM | disk | FTP | other *** search
- Path: news.acns.nwu.edu!news
- From: "Lorraine E. Long" <llong@nwu.edu>
- Newsgroups: comp.lang.c
- Subject: Re: Help with simple code
- Date: 21 Jan 1996 04:42:27 GMT
- Organization: Northwestern University, Evanston, IL, US
- Message-ID: <4dsg7j$lpu@news.acns.nwu.edu>
- References: <4dbak5$oij@ionews.io.org>
- NNTP-Posting-Host: aragorn232.nuts.nwu.edu
-
- jgordon@io.org (John Gordon MacPherson) wrote:
- >
- > Can anyone tell me what's wrong with this piece of code? I lifted it
- > straight from a textbook.
- >
- > Here's the code:
- >
- > /* Calculating compound interest */
- > #include <stdio.h>
- > #include <math.h>
- >
- > main()
- > {
- > int year;
- > double amount, principal = 1000, rate = 0.5;
- >
- > printf("%4s%21s\n", "Year", "Amount on deposit");
- >
- > for (year = 1; year <= 10; year++) {
- > amount = principal * pow(1.0 + rate, year);
- > printf("%4d%21.2f\n", year, amount);
- > }
- >
- > return 0;
- > }
- > ______________________________________________________________
- >
- > and here's the error:
- >
- > In function `main':
- > undefined reference to `pow'
- >
- > I don't understand. `pow' is a function, not a variable?
- > Can anyone tell me what's wrong?
- >
- > I don't know if you've solved this problem yet. If you have, I'd
- like to know how you did it. I have a couple of thoughts:
- The textbook I have always specifies a data type for the pow
- function, as well as for the abs function, e.g.,
- principal * double pow(. . .);
-
- Also, would it be useful to enclose the value to be raised to a power
- in parens?
- principal * double pow((1+rate), year);
-
-